<?php
set_time_limit(0);
ini_set("display_errors", "On");
error_reporting(E_ALL | E_STRICT);
 
$dbhost = '47.110.131.55';
$dbuser = 'root';
$dbpwd  ='sxy7788123456';
$dbName ='race';
$mysqli = new mysqli($dbhost, $dbuser, $dbpwd, $dbName);

$table='u3_yc';
if (isset($_GET['table'])){
    $table=$_GET['table'];
}
$arrLogTable=array(
    'u3_zz'=>'c3_log_zz',
    'u3_yc'=>'c3_log_yc',
    'u3_g3'=>'c3_log_g3',
    'u3_g2'=>'c3_log_g2',
    'u3_g1'=>'c3_log_g1',
    'u3_c3'=>'c3_log_c3',
    'u3_c2'=>'c3_log_c2',
    'u3_c1'=>'c3_log_c1'
);
$arrCTable=array(
    'u3_zz'=>'c3_zz',
    'u3_yc'=>'c3_yc',
    'u3_g3'=>'c3_g3',
    'u3_g2'=>'c3_g2',
    'u3_g1'=>'c3_g1',
    'u3_c3'=>'c3_c3',
    'u3_c2'=>'c3_c2',
    'u3_c1'=>'c3_c1'
);
$desc='ASC';
if (isset($_GET['desc'])){
    $desc='DESC';
}
$query=$mysqli->query("SELECT * FROM `".$table."` WHERE `miao` < 60 and fen > 60 order by id ".$desc."   limit 0,1  ");

$logtable=$ctable='';

$logtable=$arrLogTable[$table];
$ctable=$arrCTable[$table];

if (empty($logtable) || empty($ctable)){
    echo 'empty $logtable';
    exit;
}
$ishas=false;
while ($list=$query->fetch_assoc()){
    $id=$list['id'];
    $openid=$list['openid'];
    
    echo "fenshu: &nbsp;",$list['fen'];
    echo "<br /><br />";
    
    $sql="SELECT createtime FROM ".$ctable." where openid='".$openid."' limit 0,1 ";
    echo "ctable: &nbsp;",$sql;
    echo "<br />";
    $time='';
    $queryC=$mysqli->query($sql);
    if($queryC->num_rows>0){
        $getC=$queryC->fetch_assoc();
        $time=$list['createtime'];
        echo "has get ctime: &nbsp;&nbsp;";
        echo $time;
        $timeA=strtotime($time);
    }else{
        echo 'c time empty';
        $timeA=0;
    }
    
    echo "<br /><br />";
    echo $id,'....',$time,'....',$openid;
    echo "<br /><br />";
    echo $timeA;
    echo "<br /><br />";

    $sql="SELECT createtime FROM ".$logtable." where openid='".$openid."' limit 0,1 ";
   echo $sql;
   echo "<br /><br />";
   $queryU=$mysqli->query($sql);
    if($queryU->num_rows>0){
        $getData=$queryU->fetch_assoc();
        var_dump($getData);
        $timeB=strtotime($getData['createtime']);
        
        echo $timeB;
        echo "<br /><br />";
        
       
        echo "<br /><br />";
        if ($timeA < 1){
            $cha=-1;
        }else{
            $cha=$timeB - $timeA;
            echo "cha count: &nbsp;&nbsp;",$cha;
        }
        if ($cha < 0){
            $cha=rand(1000,1800);
        }
    }else{
        $cha=rand(1000,1800);
    }
    
    $m = floor(($cha%(3600*24))%3600/60);
    $s = floor(($cha%(3600*24))%60);
    echo "<br /><br />";
    echo $m,'....',$s;
    echo "<br /><br />";
    $miao=$m*60 + $s;
    if ($miao > 1800){
        $miao=rand(1700,1800);
    }
    echo "<br /><br />";

    if ($miao < 60){
        $miao=rand(110,600);
    }
  
    
    $sql="update ".$table." set miao=".$miao." where id='".$list['id']."' ";
    echo $sql;
    echo "<br /><br />";
    
    $mysqli->query($sql);
    
    $ishas=true;

}

if ($ishas == true){
?>
<script> 
window.setTimeout(function(){
	window.location.reload(); 
}, 100);
</script>
<?php } ?>
 
